package com.webserver.core;

import com.webserver.http.HttpContext;
import com.webserver.http.HttpServletRequest;
import com.webserver.http.HttpServletResponse;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 处理请求环节
 */
public class DispatcherServlet {
    public void service(HttpServletRequest request, HttpServletResponse response){
        String path = request.getUri();
        System.out.println("请求路径:"+path);
        File file = new File("./webapps"+path);

        if(file.isFile()){//用户请求的是一个文件
            response.setEntity(file);//设置正文
        }else{//要么不存在，要么不是一个文件
            response.setStatusCode(404);
            response.setStatusReason("NotFound");
            file = new File("./webapps/root/404.html");
            response.setEntity(file);
        }
        response.putHeader("Server","WebServer");
    }
}
